package com.guigu.oss.controller;

import com.aliyun.oss.model.MatchMode;
import com.aliyun.oss.model.PolicyConditions;
import com.guigu.oss.service.OssService;
import com.guigu.tms.result.R;
import com.guigu.tms.result.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * @ClassName:OssController
 * @Description://TODO
 * @Author:taoLong
 * @Date:2021/12/6:10:10 星期一
 * @email:2391611102@qq.com or 2391611102qq@gmail.com
 */
@RestController
@RequestMapping("/oss")
@Api(tags = "阿里云对象存储")
public class OssController {

    @Autowired
    private OssService ossService;

    @ApiOperation("上传头像请求")
    @PostMapping("/")
    public R<String> uploadOss(@ApiParam(name = "file", value = "头像上传") MultipartFile file) {
        //返回上传到oss的路径
        String url = ossService.uploadFile(file);
        return new R(ResultCode.SUCCESS_CODE, "上传成功!", true, url);
    }

    @ApiOperation("获取签名")
    @GetMapping("/getSignature")
    public R<Map> getSignature() {
        Map<String, String> signature = ossService.getSignature();
        return new R(ResultCode.SUCCESS_CODE, "获取成功!", true, signature);
    }
}
